﻿<!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
-->
<UserControl
  x:Class="System.Windows.Controls.Samples.TimePickerStudio"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:layoutToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
  xmlns:System="clr-namespace:System;assembly=mscorlib">
  <Grid
    Background="White"
    Margin="0,30,0,0">
    <Grid.ColumnDefinitions>
      <ColumnDefinition
        Width="300" />
      <ColumnDefinition
        Width="0.3*" />
      <ColumnDefinition
        Width="0.4*" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
      <RowDefinition />
      <RowDefinition />
      <RowDefinition />
      <RowDefinition />
      <RowDefinition />
      <RowDefinition />
      <RowDefinition />
      <RowDefinition />
      <RowDefinition />
      <RowDefinition />
      <RowDefinition />
    </Grid.RowDefinitions>
    <ContentControl
      Grid.RowSpan="2"
      Content="Change properties"
      Style="{StaticResource Header}" />
    <layoutToolkit:TimePicker
      x:Name="tp"
      Grid.RowSpan="10"
      Grid.Column="0"
      Width="200"
      HorizontalAlignment="Left"
      VerticalAlignment="Center" />
    <TextBlock
      Text="Minimum"
      Grid.Row="0"
      Grid.Column="1"
      Margin="3" />
    <layoutToolkit:TimePicker
      Grid.Row="0"
      Grid.Column="2"
      Width="160"
      Margin="3"
      HorizontalAlignment="Left"
      ValueChanged="MinimumChanged" />
    <TextBlock
      Text="Maximum"
      Grid.Row="1"
      Grid.Column="1"
      Margin="3" />
    <layoutToolkit:TimePicker
      Grid.Row="1"
      Grid.Column="2"
      Width="160"
      Margin="3"
      HorizontalAlignment="Left"
      ValueChanged="MaximumChanged" />
    <TextBlock
      Text="TimeParsers"
      Grid.Row="4"
      Grid.Column="1"
      Margin="3" />
    <ComboBox
      x:Name="cmbTimeParser"
      DisplayMemberPath="Key"
      Grid.Row="4"
      Grid.Column="2"
      Margin="3"
      SelectionChanged="TimeparserChanged" />
    <TextBlock
      Text="Format"
      Grid.Row="5"
      Grid.Column="1"
      Margin="3" />
    <ComboBox
      x:Name="cmbFormat"
      DisplayMemberPath="Key"
      Grid.Row="5"
      Grid.Column="2"
      Margin="3"
      SelectionChanged="FormatChanged" />
    <TextBlock
      Text="Culture"
      Grid.Row="6"
      Grid.Column="1"
      Margin="3" />
    <ComboBox
      x:Name="cmbCultures"
      Grid.Row="6"
      Grid.Column="2"
      Margin="3"
      DisplayMemberPath="EnglishName"
      SelectionChanged="CultureChanged" />
    <TextBlock
      Text="Popup"
      Grid.Row="7"
      Grid.Column="1"
      Margin="3" />
    <ComboBox
      x:Name="cmbPopup"
      Grid.Row="7"
      Grid.Column="2"
      Margin="3"
      DisplayMemberPath="Key"
      SelectionChanged="PopupChanged" />
    <TextBlock
      Text="Popup seconds interval"
      Grid.Row="8"
      Grid.Column="1"
      Margin="3" />
    <ComboBox
      x:Name="cmbPopupSecondsInterval"
      Grid.Row="8"
      Grid.Column="2"
      Margin="3"
      SelectionChanged="PopupSecondsIntervalChanged">
      <System:Int32>1</System:Int32>
      <System:Int32>5</System:Int32>
      <System:Int32>10</System:Int32>
      <System:Int32>15</System:Int32>
      <System:Int32>20</System:Int32>
    </ComboBox>
    <TextBlock
      Text="Popup minutes interval"
      Grid.Row="9"
      Grid.Column="1"
      Margin="3" />
    <ComboBox
      x:Name="cmbPopupMinutesInterval"
      Grid.Row="9"
      Grid.Column="2"
      Margin="3"
      SelectionChanged="PopupMinutesIntervalChanged">
      <System:Int32>1</System:Int32>
      <System:Int32>5</System:Int32>
      <System:Int32>10</System:Int32>
      <System:Int32>12</System:Int32>
      <System:Int32>15</System:Int32>
      <System:Int32>20</System:Int32>
      <System:Int32>30</System:Int32>
    </ComboBox>
    <TextBlock
      Text="Popup selection mode"
      Grid.Row="10"
      Grid.Column="1"
      Margin="3" />
    <ComboBox
      x:Name="cmbPopupSelectionMode"
      Grid.Row="10"
      Grid.Column="2"
      Margin="3"
      SelectionChanged="PopupSelectionModeChanged"></ComboBox>
    <src:SourceViewer xmlns:src="clr-namespace:System.Windows.Controls.Samples;assembly=System.Windows.Controls.Samples.Common" xmlns:sys="clr-namespace:System;assembly=mscorlib">
  <src:SourceFile Path="TimePickerStudio.xaml">
    <src:SourceFile.Source>
      <sys:String>&lt;!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
--&gt;
&lt;UserControl
  x:Class="System.Windows.Controls.Samples.TimePickerStudio"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:layoutToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
  xmlns:System="clr-namespace:System;assembly=mscorlib"&gt;
  &lt;Grid
    Background="White"
    Margin="0,30,0,0"&gt;
    &lt;Grid.ColumnDefinitions&gt;
      &lt;ColumnDefinition
        Width="300" /&gt;
      &lt;ColumnDefinition
        Width="0.3*" /&gt;
      &lt;ColumnDefinition
        Width="0.4*" /&gt;
    &lt;/Grid.ColumnDefinitions&gt;
    &lt;Grid.RowDefinitions&gt;
      &lt;RowDefinition /&gt;
      &lt;RowDefinition /&gt;
      &lt;RowDefinition /&gt;
      &lt;RowDefinition /&gt;
      &lt;RowDefinition /&gt;
      &lt;RowDefinition /&gt;
      &lt;RowDefinition /&gt;
      &lt;RowDefinition /&gt;
      &lt;RowDefinition /&gt;
      &lt;RowDefinition /&gt;
      &lt;RowDefinition /&gt;
    &lt;/Grid.RowDefinitions&gt;
    &lt;ContentControl
      Grid.RowSpan="2"
      Content="Change properties"
      Style="{StaticResource Header}" /&gt;
    &lt;layoutToolkit:TimePicker
      x:Name="tp"
      Grid.RowSpan="10"
      Grid.Column="0"
      Width="200"
      HorizontalAlignment="Left"
      VerticalAlignment="Center" /&gt;
    &lt;TextBlock
      Text="Minimum"
      Grid.Row="0"
      Grid.Column="1"
      Margin="3" /&gt;
    &lt;layoutToolkit:TimePicker
      Grid.Row="0"
      Grid.Column="2"
      Width="160"
      Margin="3"
      HorizontalAlignment="Left"
      ValueChanged="MinimumChanged" /&gt;
    &lt;TextBlock
      Text="Maximum"
      Grid.Row="1"
      Grid.Column="1"
      Margin="3" /&gt;
    &lt;layoutToolkit:TimePicker
      Grid.Row="1"
      Grid.Column="2"
      Width="160"
      Margin="3"
      HorizontalAlignment="Left"
      ValueChanged="MaximumChanged" /&gt;
    &lt;TextBlock
      Text="TimeParsers"
      Grid.Row="4"
      Grid.Column="1"
      Margin="3" /&gt;
    &lt;ComboBox
      x:Name="cmbTimeParser"
      DisplayMemberPath="Key"
      Grid.Row="4"
      Grid.Column="2"
      Margin="3"
      SelectionChanged="TimeparserChanged" /&gt;
    &lt;TextBlock
      Text="Format"
      Grid.Row="5"
      Grid.Column="1"
      Margin="3" /&gt;
    &lt;ComboBox
      x:Name="cmbFormat"
      DisplayMemberPath="Key"
      Grid.Row="5"
      Grid.Column="2"
      Margin="3"
      SelectionChanged="FormatChanged" /&gt;
    &lt;TextBlock
      Text="Culture"
      Grid.Row="6"
      Grid.Column="1"
      Margin="3" /&gt;
    &lt;ComboBox
      x:Name="cmbCultures"
      Grid.Row="6"
      Grid.Column="2"
      Margin="3"
      DisplayMemberPath="EnglishName"
      SelectionChanged="CultureChanged" /&gt;
    &lt;TextBlock
      Text="Popup"
      Grid.Row="7"
      Grid.Column="1"
      Margin="3" /&gt;
    &lt;ComboBox
      x:Name="cmbPopup"
      Grid.Row="7"
      Grid.Column="2"
      Margin="3"
      DisplayMemberPath="Key"
      SelectionChanged="PopupChanged" /&gt;
    &lt;TextBlock
      Text="Popup seconds interval"
      Grid.Row="8"
      Grid.Column="1"
      Margin="3" /&gt;
    &lt;ComboBox
      x:Name="cmbPopupSecondsInterval"
      Grid.Row="8"
      Grid.Column="2"
      Margin="3"
      SelectionChanged="PopupSecondsIntervalChanged"&gt;
      &lt;System:Int32&gt;1&lt;/System:Int32&gt;
      &lt;System:Int32&gt;5&lt;/System:Int32&gt;
      &lt;System:Int32&gt;10&lt;/System:Int32&gt;
      &lt;System:Int32&gt;15&lt;/System:Int32&gt;
      &lt;System:Int32&gt;20&lt;/System:Int32&gt;
    &lt;/ComboBox&gt;
    &lt;TextBlock
      Text="Popup minutes interval"
      Grid.Row="9"
      Grid.Column="1"
      Margin="3" /&gt;
    &lt;ComboBox
      x:Name="cmbPopupMinutesInterval"
      Grid.Row="9"
      Grid.Column="2"
      Margin="3"
      SelectionChanged="PopupMinutesIntervalChanged"&gt;
      &lt;System:Int32&gt;1&lt;/System:Int32&gt;
      &lt;System:Int32&gt;5&lt;/System:Int32&gt;
      &lt;System:Int32&gt;10&lt;/System:Int32&gt;
      &lt;System:Int32&gt;12&lt;/System:Int32&gt;
      &lt;System:Int32&gt;15&lt;/System:Int32&gt;
      &lt;System:Int32&gt;20&lt;/System:Int32&gt;
      &lt;System:Int32&gt;30&lt;/System:Int32&gt;
    &lt;/ComboBox&gt;
    &lt;TextBlock
      Text="Popup selection mode"
      Grid.Row="10"
      Grid.Column="1"
      Margin="3" /&gt;
    &lt;ComboBox
      x:Name="cmbPopupSelectionMode"
      Grid.Row="10"
      Grid.Column="2"
      Margin="3"
      SelectionChanged="PopupSelectionModeChanged"&gt;&lt;/ComboBox&gt;
  &lt;/Grid&gt;
&lt;/UserControl&gt;
</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="TimePickerStudio.xaml.cs">
    <src:SourceFile.Source>
      <sys:String>// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Collections.Generic;

namespace System.Windows.Controls.Samples
{
    /// &lt;summary&gt;
    /// Sample that allows setting properties on a TimePicker.
    /// &lt;/summary&gt;
    [Sample("(3)TimePicker Studio", DifficultyLevel.Intermediate)]
    [Category("TimePicker")]
    public partial class TimePickerStudio : UserControl
    {
        #region Cultures
        /// &lt;summary&gt;
        /// Cultures that are recognized on most configurations.
        /// &lt;/summary&gt;
        private readonly string[] _cultureNames = new[]
                                             {
                                                     "af", "af-ZA", "ar", "ar-AE", "ar-BH", "ar-DZ", "ar-EG", "ar-IQ", "ar-JO", "ar-KW", "ar-LB", "ar-LY",
                                                     "ar-MA", "ar-OM", "ar-QA", "ar-SA", "ar-SY", "ar-TN", "ar-YE", "az", "az-Cyrl-AZ", "az-Latn-AZ", "be",
                                                     "be-BY", "bg", "bg-BG", "ca", "ca-ES", "cs", "cs-CZ", "da", "da-DK", "de", "de-AT", "de-CH", "de-DE",
                                                     "de-LI", "de-LU", "dv", "dv-MV", "el", "el-GR", "en", "en-029", "en-AU", "en-BZ", "en-CA", "en-GB", "en-IE", 
                                                     "en-JM", "en-NZ", "en-PH", "en-TT", "en-US", "en-ZA", "en-ZW", "es", "es-AR", "es-BO", "es-CL", "es-CO",
                                                     "es-CR", "es-DO", "es-EC", "es-ES", "es-GT", "es-HN", "es-MX", "es-NI", "es-PA", "es-PE", "es-PR", "es-PY",
                                                     "es-SV", "es-UY", "es-VE", "et", "et-EE", "eu", "eu-ES", "fa", "fa-IR", "fi", "fi-FI", "fo", "fo-FO", "fr",
                                                     "fr-BE", "fr-CA", "fr-CH", "fr-FR", "fr-LU", "fr-MC", "gl", "gl-ES", "gu", "gu-IN", "he", "he-IL", "hi",
                                                     "hi-IN", "hr", "hr-HR", "hu", "hu-HU", "hy", "hy-AM", "id", "id-ID", "is", "is-IS", "it", "it-CH", "it-IT",
                                                     "ja", "ja-JP", "ka", "ka-GE", "kk", "kk-KZ", "kn", "kn-IN", "ko", "kok", "kok-IN", "ko-KR", "ky", "ky-KG",
                                                     "lt", "lt-LT", "lv", "lv-LV", "mk", "mk-MK", "mn", "mn-MN", "mr", "mr-IN", "ms", "ms-BN", "ms-MY", "nb-NO",
                                                     "nl", "nl-BE", "nl-NL", "nn-NO", "no", "pa", "pa-IN", "pl", "pl-PL", "pt", "pt-BR", "pt-PT", "ro", "ro-RO",
                                                     "ru", "ru-RU", "sa", "sa-IN", "sk", "sk-SK", "sl", "sl-SI", "sq", "sq-AL", "sr", "sr-Cyrl-CS", "sr-Latn-CS", 
                                                     "sv", "sv-FI", "sv-SE", "sw", "sw-KE", "syr", "syr-SY", "ta", "ta-IN", "te", "te-IN", "th", "th-TH", "tr", 
                                                     "tr-TR", "tt", "tt-RU", "uk", "uk-UA", "ur", "ur-PK", "uz", "uz-Cyrl-UZ", "uz-Latn-UZ", "vi", "vi-VN",
                                                     "zh-CHS", "zh-CHT", "zh-CN", "zh-HK", "zh-MO", "zh-SG", "zh-TW"
                                             };
        #endregion
        /// &lt;summary&gt;
        /// Initializes a new instance of the &lt;see cref="TimePickerStudio"/&gt; class.
        /// &lt;/summary&gt;
        public TimePickerStudio()
        {
            InitializeComponent();

            Loaded += TimePickerStudio_Loaded;
        }

        /// &lt;summary&gt;
        /// Handles the Loaded event of the TimePickerStudio control.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;The source of the event.&lt;/param&gt;
        /// &lt;param name="e"&gt;The &lt;see cref="System.Windows.RoutedEventArgs"/&gt; instance containing the event data.&lt;/param&gt;
        private void TimePickerStudio_Loaded(object sender, RoutedEventArgs e)
        {
            // init
            cmbPopupSelectionMode.ItemsSource = typeof(PopupTimeSelectionMode)
                .GetMembers()
                .ToList()
                .Where(m =&gt;
                    m.DeclaringType.Equals(typeof(PopupTimeSelectionMode)) &amp;&amp;
                    !m.Name.StartsWith("_", StringComparison.Ordinal) &amp;&amp;
                    !m.Name.EndsWith("_", StringComparison.Ordinal))
                .Select(m =&gt; m.Name)
                .ToList();

            cmbPopup.ItemsSource = new Dictionary&lt;string, Type&gt;()
                                       {
                                           { "ListTimePicker", typeof(ListTimePickerPopup) },
                                           { "RangeTimePicker", typeof(RangeTimePickerPopup) },
                                       };

            cmbFormat.ItemsSource = new Dictionary&lt;string, ITimeFormat&gt;()
                                        {
                                            { "ShortTimeFormat", new ShortTimeFormat() },
                                            { "LongTimeFormat", new LongTimeFormat() },
                                            { "Custom: hh:mm:ss", new CustomTimeFormat("hh:mm:ss") },
                                            { "Custom: hh.mm", new CustomTimeFormat("hh.mm") },
                                        };

            cmbTimeParser.ItemsSource = new Dictionary&lt;string, TimeParser&gt;()
                                            {
                                                { "+/- hours, try +3h", new PlusMinusHourTimeParser() },
                                                { "+/- minutes, try +3m", new PlusMinusMinuteTimeInputParser() },
                                            };

            // defaults
            cmbFormat.SelectedIndex = 0;
            cmbPopupSecondsInterval.SelectedIndex = 1;
            cmbPopupMinutesInterval.SelectedIndex = 3;
            cmbPopupSelectionMode.SelectedIndex = cmbPopupSelectionMode.Items.ToList().IndexOf(tp.PopupTimeSelectionMode.ToString());
            cmbPopup.SelectedIndex = 0;

            List&lt;CultureInfo&gt; cultures = new List&lt;CultureInfo&gt;();

            // work through long list of cultures and check if it is actually 
            // allowed in this configuration.
            foreach (string cultureName in _cultureNames)
            {
                try
                {
                    CultureInfo c = new CultureInfo(cultureName);
                    cultures.Add(c);
                }
                catch (ArgumentException)
                {
                }
            }

            cmbCultures.ItemsSource = cultures;
            // preselect current culture.
            cmbCultures.SelectedItem = cultures.FirstOrDefault(info =&gt; info.Name == tp.ActualCulture.Name);
        }

        /// &lt;summary&gt;
        /// Called when Minimum ComboBox is changed.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;The sender.&lt;/param&gt;
        /// &lt;param name="e"&gt;The instance containing the event data.&lt;/param&gt;
        [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Hooked up in Xaml.")]
        private void MinimumChanged(object sender, RoutedPropertyChangedEventArgs&lt;DateTime?&gt; e)
        {
            tp.Minimum = e.NewValue;
        }

        /// &lt;summary&gt;
        /// Called when Maximum ComboBox is changed.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;The sender.&lt;/param&gt;
        /// &lt;param name="e"&gt;The instance containing the event data.&lt;/param&gt;
        [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Hooked up in Xaml.")]
        private void MaximumChanged(object sender, RoutedPropertyChangedEventArgs&lt;DateTime?&gt; e)
        {
            tp.Maximum = e.NewValue;
        }

        /// &lt;summary&gt;
        /// Called when Popup ComboBox is changed.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;The sender.&lt;/param&gt;
        /// &lt;param name="e"&gt;The &lt;see cref="System.Windows.Controls.SelectionChangedEventArgs"/&gt; instance containing the event data.&lt;/param&gt;
        [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Hooked up in Xaml.")]
        private void PopupChanged(object sender, SelectionChangedEventArgs e)
        {
            tp.Popup = Activator.CreateInstance(((KeyValuePair&lt;string, Type&gt;)cmbPopup.SelectedItem).Value) as TimePickerPopup;
        }

        /// &lt;summary&gt;
        /// Called when PopupSecondsInterval ComboBox is changed.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;The sender.&lt;/param&gt;
        /// &lt;param name="e"&gt;The &lt;see cref="System.Windows.Controls.SelectionChangedEventArgs"/&gt; instance containing the event data.&lt;/param&gt;
        [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Hooked up in Xaml.")]
        private void PopupSecondsIntervalChanged(object sender, SelectionChangedEventArgs e)
        {
            tp.PopupSecondsInterval = (int)e.AddedItems[0];
        }

        /// &lt;summary&gt;
        /// Called when PopupMinutesInterval ComboBox is changed.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;The sender.&lt;/param&gt;
        /// &lt;param name="e"&gt;The &lt;see cref="System.Windows.Controls.SelectionChangedEventArgs"/&gt; instance containing the event data.&lt;/param&gt;
        [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Hooked up in Xaml.")]
        private void PopupMinutesIntervalChanged(object sender, SelectionChangedEventArgs e)
        {
            tp.PopupMinutesInterval = (int)e.AddedItems[0];
        }

        /// &lt;summary&gt;
        /// Called when the PopupSelectionMode ComboBox is changed.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;The sender.&lt;/param&gt;
        /// &lt;param name="e"&gt;The &lt;see cref="System.Windows.Controls.SelectionChangedEventArgs"/&gt; instance containing the event data.&lt;/param&gt;
        [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Hooked up in Xaml.")]
        private void PopupSelectionModeChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                tp.PopupTimeSelectionMode = (PopupTimeSelectionMode)Enum.Parse(typeof(PopupTimeSelectionMode), e.AddedItems[0].ToString(), false);
            }
            catch (ArgumentOutOfRangeException)
            {
                Dispatcher.BeginInvoke(() =&gt;
                                       cmbPopupSelectionMode.SelectedIndex =
                                       cmbPopupSelectionMode.Items.ToList().IndexOf(e.RemovedItems[0]));
            }
        }

        /// &lt;summary&gt;
        /// Called when Culture ComboBox has changed.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;The sender.&lt;/param&gt;
        /// &lt;param name="e"&gt;The &lt;see cref="System.Windows.Controls.SelectionChangedEventArgs"/&gt; 
        /// instance containing the event data.&lt;/param&gt;
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Wish to catch all."), SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Hooked up in Xaml.")]
        private void CultureChanged(object sender, SelectionChangedEventArgs e)
        {
            if (cmbCultures.SelectedItem != null)
            {
                tp.Culture = (CultureInfo)cmbCultures.SelectedItem;
            }
        }

        /// &lt;summary&gt;
        /// Called when Format ComboBox has changed.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;The sender.&lt;/param&gt;
        /// &lt;param name="e"&gt;The &lt;see cref="System.Windows.Controls.SelectionChangedEventArgs"/&gt; 
        /// instance containing the event data.&lt;/param&gt;
        [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Hooked up in Xaml.")]
        private void FormatChanged(object sender, SelectionChangedEventArgs e)
        {
            tp.Format = ((KeyValuePair&lt;string, ITimeFormat&gt;)cmbFormat.SelectedItem).Value;
        }

        /// &lt;summary&gt;
        /// Called when Timeparsers ComboBox is changed.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;The sender.&lt;/param&gt;
        /// &lt;param name="e"&gt;The &lt;see cref="System.Windows.Controls.SelectionChangedEventArgs"/&gt; 
        /// instance containing the event data.&lt;/param&gt;
        [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Hooked up in Xaml.")]
        private void TimeparserChanged(object sender, SelectionChangedEventArgs e)
        {
            tp.TimeParsers = new TimeParserCollection
                                 {
                                     ((KeyValuePair&lt;string, TimeParser&gt;)cmbTimeParser.SelectedItem).Value
                                 };
        }
    }
}
</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="TimePickerStudio.xaml.vb">
    <src:SourceFile.Source>
      <sys:String>' (c) Copyright Microsoft Corporation.
' This source is subject to the Microsoft Public License (Ms-PL).
' Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
' All other rights reserved.

Imports Microsoft.VisualBasic
Imports System.ComponentModel
Imports System.Diagnostics.CodeAnalysis
Imports System.Globalization
Imports System.Linq
Imports System.Collections.Generic

''' &lt;summary&gt;
''' Sample that allows setting properties on a TimePicker.
''' &lt;/summary&gt;
&lt;Sample("(3)TimePicker Studio", DifficultyLevel.Intermediate), Category("TimePicker")&gt; _
Partial Public Class TimePickerStudio
    Inherits UserControl

    ''' &lt;summary&gt;
    ''' Cultures that are recognized on most configurations.
    ''' &lt;/summary&gt;
    Private ReadOnly _cultureNames As String() = New String() {"af", "af-ZA", "ar", "ar-AE", "ar-BH", "ar-DZ", _
    "ar-EG", "ar-IQ", "ar-JO", "ar-KW", "ar-LB", "ar-LY", _
    "ar-MA", "ar-OM", "ar-QA", "ar-SA", "ar-SY", "ar-TN", _
    "ar-YE", "az", "az-Cyrl-AZ", "az-Latn-AZ", "be", "be-BY", _
    "bg", "bg-BG", "ca", "ca-ES", "cs", "cs-CZ", _
    "da", "da-DK", "de", "de-AT", "de-CH", "de-DE", _
    "de-LI", "de-LU", "dv", "dv-MV", "el", "el-GR", _
    "en", "en-029", "en-AU", "en-BZ", "en-CA", "en-GB", _
    "en-IE", "en-JM", "en-NZ", "en-PH", "en-TT", "en-US", _
    "en-ZA", "en-ZW", "es", "es-AR", "es-BO", "es-CL", _
    "es-CO", "es-CR", "es-DO", "es-EC", "es-ES", "es-GT", _
    "es-HN", "es-MX", "es-NI", "es-PA", "es-PE", "es-PR", _
    "es-PY", "es-SV", "es-UY", "es-VE", "et", "et-EE", _
    "eu", "eu-ES", "fa", "fa-IR", "fi", "fi-FI", _
    "fo", "fo-FO", "fr", "fr-BE", "fr-CA", "fr-CH", _
    "fr-FR", "fr-LU", "fr-MC", "gl", "gl-ES", "gu", _
    "gu-IN", "he", "he-IL", "hi", "hi-IN", "hr", _
    "hr-HR", "hu", "hu-HU", "hy", "hy-AM", "id", _
    "id-ID", "is", "is-IS", "it", "it-CH", "it-IT", _
    "ja", "ja-JP", "ka", "ka-GE", "kk", "kk-KZ", _
    "kn", "kn-IN", "ko", "kok", "kok-IN", "ko-KR", _
    "ky", "ky-KG", "lt", "lt-LT", "lv", "lv-LV", _
    "mk", "mk-MK", "mn", "mn-MN", "mr", "mr-IN", _
    "ms", "ms-BN", "ms-MY", "nb-NO", "nl", "nl-BE", _
    "nl-NL", "nn-NO", "no", "pa", "pa-IN", "pl", _
    "pl-PL", "pt", "pt-BR", "pt-PT", "ro", "ro-RO", _
    "ru", "ru-RU", "sa", "sa-IN", "sk", "sk-SK", _
    "sl", "sl-SI", "sq", "sq-AL", "sr", "sr-Cyrl-CS", _
    "sr-Latn-CS", "sv", "sv-FI", "sv-SE", "sw", "sw-KE", _
    "syr", "syr-SY", "ta", "ta-IN", "te", "te-IN", _
    "th", "th-TH", "tr", "tr-TR", "tt", "tt-RU", _
    "uk", "uk-UA", "ur", "ur-PK", "uz", "uz-Cyrl-UZ", _
    "uz-Latn-UZ", "vi", "vi-VN", "zh-CHS", "zh-CHT", "zh-CN", _
    "zh-HK", "zh-MO", "zh-SG", "zh-TW"}

    ''' &lt;summary&gt;
    ''' Initializes a new instance of the &lt;see cref="TimePickerStudio"/&gt; class.
    ''' &lt;/summary&gt;
    Public Sub New()
        InitializeComponent()
    End Sub

    ''' &lt;summary&gt;
    ''' Handles the Loaded event of the TimePickerStudio control.
    ''' &lt;/summary&gt;
    ''' &lt;param name="sender"&gt;The source of the event.&lt;/param&gt;
    ''' &lt;param name="e"&gt;The &lt;see cref="System.Windows.RoutedEventArgs"/&gt; instance containing the event data.&lt;/param&gt;
    Private Sub TimePickerStudio_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles Me.Loaded
        ' init
        cmbPopupSelectionMode.ItemsSource = GetType(PopupTimeSelectionMode) _
        .GetMembers() _
        .ToList() _
        .Where(Function(m) _
                   m.DeclaringType.Equals(GetType(PopupTimeSelectionMode)) AndAlso _
                   (Not m.Name.StartsWith("_", StringComparison.Ordinal)) AndAlso _
                   (Not m.Name.EndsWith("_", StringComparison.Ordinal))) _
        .Select(Function(m) m.Name) _
        .ToList()

        Dim myItemsSource As New Dictionary(Of String, Type)()
        myItemsSource.Add("ListTimePicker", GetType(ListTimePickerPopup))
        myItemsSource.Add("RangeTimePicker", GetType(RangeTimePickerPopup))
        cmbPopup.ItemsSource = myItemsSource

        Dim myFormatSource As New Dictionary(Of String, ITimeFormat)()
        myFormatSource.Add("ShortTimeFormat", New ShortTimeFormat())
        myFormatSource.Add("LongTimeFormat", New LongTimeFormat())
        myFormatSource.Add("Custom: hh:mm:ss", New CustomTimeFormat("hh:mm:ss"))
        myFormatSource.Add("Custom: hh.mm", New CustomTimeFormat("hh.mm"))
        cmbFormat.ItemsSource = myFormatSource

        Dim myTimeParserSource As New Dictionary(Of String, TimeParser)()
        myTimeParserSource.Add("+/- hours, try +3h", New PlusMinusHourTimeParser())
        myTimeParserSource.Add("+/- minutes, try +3m", New PlusMinusMinuteTimeInputParser())
        cmbTimeParser.ItemsSource = myTimeParserSource

        ' defaults
        cmbFormat.SelectedIndex = 0
        cmbPopupSecondsInterval.SelectedIndex = 1
        cmbPopupMinutesInterval.SelectedIndex = 3
        cmbPopupSelectionMode.SelectedIndex = cmbPopupSelectionMode.Items.ToList().IndexOf(tp.PopupTimeSelectionMode.ToString())
        cmbPopup.SelectedIndex = 0

        Dim cultures As New List(Of CultureInfo)()

        ' work through long list of cultures and check if it is actually 
        ' allowed in this configuration.
        For Each cultureName As String In _cultureNames
            Try
                Dim c As New CultureInfo(cultureName)
                cultures.Add(c)
            Catch generatedExceptionName As ArgumentException
            End Try
        Next

        cmbCultures.ItemsSource = cultures
        ' preselect current culture.
        cmbCultures.SelectedItem = cultures.FirstOrDefault(Function(info) info.Name = tp.ActualCulture.Name)
    End Sub

    ''' &lt;summary&gt;
    ''' Called when Minimum ComboBox is changed.
    ''' &lt;/summary&gt;
    ''' &lt;param name="sender"&gt;The sender.&lt;/param&gt;
    ''' &lt;param name="e"&gt;The instance containing the event data.&lt;/param&gt;
    &lt;SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification:="Hooked up in Xaml.")&gt; _
    Private Sub MinimumChanged(ByVal sender As Object, ByVal e As RoutedPropertyChangedEventArgs(Of DateTime?))
        tp.Minimum = e.NewValue
    End Sub

    ''' &lt;summary&gt;
    ''' Called when Maximum ComboBox is changed.
    ''' &lt;/summary&gt;
    ''' &lt;param name="sender"&gt;The sender.&lt;/param&gt;
    ''' &lt;param name="e"&gt;The instance containing the event data.&lt;/param&gt;
    &lt;SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification:="Hooked up in Xaml.")&gt; _
    Private Sub MaximumChanged(ByVal sender As Object, ByVal e As RoutedPropertyChangedEventArgs(Of DateTime?))
        tp.Maximum = e.NewValue
    End Sub

    ''' &lt;summary&gt;
    ''' Called when Popup ComboBox is changed.
    ''' &lt;/summary&gt;
    ''' &lt;param name="sender"&gt;The sender.&lt;/param&gt;
    ''' &lt;param name="e"&gt;The &lt;see cref="System.Windows.Controls.SelectionChangedEventArgs"/&gt; instance containing the event data.&lt;/param&gt;
    &lt;SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification:="Hooked up in Xaml.")&gt; _
    Private Sub PopupChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)
        tp.Popup = TryCast(Activator.CreateInstance((CType(cmbPopup.SelectedItem, KeyValuePair(Of String, Type))).Value), TimePickerPopup)
    End Sub

    ''' &lt;summary&gt;
    ''' Called when PopupSecondsInterval ComboBox is changed.
    ''' &lt;/summary&gt;
    ''' &lt;param name="sender"&gt;The sender.&lt;/param&gt;
    ''' &lt;param name="e"&gt;The &lt;see cref="System.Windows.Controls.SelectionChangedEventArgs"/&gt; instance containing the event data.&lt;/param&gt;
    &lt;SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification:="Hooked up in Xaml.")&gt; _
    Private Sub PopupSecondsIntervalChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)
        tp.PopupSecondsInterval = CInt(Fix(e.AddedItems(0)))
    End Sub

    ''' &lt;summary&gt;
    ''' Called when PopupMinutesInterval ComboBox is changed.
    ''' &lt;/summary&gt;
    ''' &lt;param name="sender"&gt;The sender.&lt;/param&gt;
    ''' &lt;param name="e"&gt;The &lt;see cref="System.Windows.Controls.SelectionChangedEventArgs"/&gt; instance containing the event data.&lt;/param&gt;
    &lt;SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification:="Hooked up in Xaml.")&gt; _
    Private Sub PopupMinutesIntervalChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)
        tp.PopupMinutesInterval = CInt(Fix(e.AddedItems(0)))
    End Sub

    ''' &lt;summary&gt;
    ''' Called when the PopupSelectionMode ComboBox is changed.
    ''' &lt;/summary&gt;
    ''' &lt;param name="sender"&gt;The sender.&lt;/param&gt;
    ''' &lt;param name="e"&gt;The &lt;see cref="System.Windows.Controls.SelectionChangedEventArgs"/&gt; instance containing the event data.&lt;/param&gt;
    &lt;SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification:="Hooked up in Xaml.")&gt; _
    Private Sub PopupSelectionModeChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)
        Try
            tp.PopupTimeSelectionMode = CType([Enum].Parse(GetType(PopupTimeSelectionMode), e.AddedItems(0).ToString(), False), PopupTimeSelectionMode)
        Catch ex As ArgumentOutOfRangeException
            Dispatcher.BeginInvoke(New SelectionChangedEventHandler(AddressOf AsyncPopupSelectionChanged), sender, e)
        End Try
    End Sub

    ''' &lt;summary&gt;
    ''' Called asynchronously when the PopupSelectionMode ComboBox is changed.
    ''' &lt;/summary&gt;
    ''' &lt;param name="sender"&gt;The sender.&lt;/param&gt;
    ''' &lt;param name="e"&gt;The &lt;see cref="System.Windows.Controls.SelectionChangedEventArgs"/&gt; instance containing the event data.&lt;/param&gt;
    Private Sub AsyncPopupSelectionChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)
        cmbPopupSelectionMode.SelectedIndex = cmbPopupSelectionMode.Items.ToList().IndexOf(e.RemovedItems(0))
    End Sub

    ''' &lt;summary&gt;
    ''' Called when Culture ComboBox has changed.
    ''' &lt;/summary&gt;
    ''' &lt;param name="sender"&gt;The sender.&lt;/param&gt;
    ''' &lt;param name="e"&gt;The &lt;see cref="System.Windows.Controls.SelectionChangedEventArgs"/&gt; 
    ''' instance containing the event data.&lt;/param&gt;
    &lt;SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification:="Wish to catch all."), SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification:="Hooked up in Xaml.")&gt; _
    Private Sub CultureChanged(ByVal sender As Object, ByVal e As RoutedEventArgs)
        If cmbCultures.SelectedItem IsNot Nothing Then
            tp.Culture = DirectCast(cmbCultures.SelectedItem, CultureInfo)
        End If
    End Sub

    ''' &lt;summary&gt;
    ''' Called when Format ComboBox has changed.
    ''' &lt;/summary&gt;
    ''' &lt;param name="sender"&gt;The sender.&lt;/param&gt;
    ''' &lt;param name="e"&gt;The &lt;see cref="System.Windows.Controls.SelectionChangedEventArgs"/&gt; 
    ''' instance containing the event data.&lt;/param&gt;
    &lt;SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification:="Hooked up in Xaml.")&gt; _
    Private Sub FormatChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)
        tp.Format = (CType(cmbFormat.SelectedItem, KeyValuePair(Of String, ITimeFormat))).Value
    End Sub

    ''' &lt;summary&gt;
    ''' Called when Timeparsers ComboBox is changed.
    ''' &lt;/summary&gt;
    ''' &lt;param name="sender"&gt;The sender.&lt;/param&gt;
    ''' &lt;param name="e"&gt;The &lt;see cref="System.Windows.Controls.SelectionChangedEventArgs"/&gt; 
    ''' instance containing the event data.&lt;/param&gt;
    &lt;SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification:="Hooked up in Xaml.")&gt; _
    Private Sub TimeparserChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)
        Dim myTimeParserCollection As New TimeParserCollection()
        myTimeParserCollection.Add((CType(cmbTimeParser.SelectedItem, KeyValuePair(Of String, TimeParser))).Value)
        tp.TimeParsers = myTimeParserCollection
    End Sub
End Class
</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
</src:SourceViewer>
  </Grid>
</UserControl>
